//
// Created by mazaiting on 2024/4/27.
//

#include <bits/stdc++.h>

using namespace std;

int Sum3(int n)           //求和算法3
{
    if (n < 1)
        throw "参数n错误";        //抛出异常信息
    return n * (n + 1) / 2;
}

int main() {
    try
    {
        int n = -5;
        printf("1到%d的和=%d\n", n, Sum3(n));
    }
    catch (const char *str)
    {
        cout << str << endl;
    }
    return 0;
}